package com.xueqiu.movieplaymanagersystem.model;

import java.io.Serializable;
import java.util.List;

/**
 * @author xueqiu
 */
public class JsonResult<T> implements Serializable {
    public static final Long serialVersionUID = 1L;

    /**
     * 结果消息
     */
    private String msg;

    /**
     * 结果状态码
     * error 0
     * success 1
     */
    private int code;

    /**
     * 结果数据
     */
    private List<T> data;

    /**
     * 结果数量；可以为0
     */
    private int count;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public void Success() {
        setCode(1);
    }

    public void Success(String message){
        setCode(1);
        setMsg(message);
    }

    public void Success(List<T> data){
        setCode(1);
        setData(data);
    }

    public void Success(String message, List<T> data){
        setCode(1);
        setMsg(message);
        setData(data);
    }

    public void Success(String message, List<T> data, int total){
        setCode(1);
        setMsg(message);
        setData(data);
        setCount(total);
    }

    public void Error() {
        setCode(2);
    }

    public void Error(String message){
        setCode(2);
        setMsg(message);
    }

    @Override
    public String toString() {
        return "JsonResult{" +
                "msg='" + msg + '\'' +
                ", code=" + code +
                ", data=" + data +
                ", count=" + count +
                '}';
    }
}
